use derive_builder::Builder;
use serde::{Deserialize, Serialize};

use crate::database::{DataSource, DatabaseType};
use crate::error::Error;
use crate::modeling::{Class, Value};

#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
pub struct DataValueSet<M, S> {
    /// 元数据
    pub meta_data: Option<M>,
    /// 返回数据概述
    pub headers: Option<S>,
    /// 数据
    pub data: Vec<Value>,
}

#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
pub struct DataValue<M, S> {
    /// 元数据
    pub meta_data: Option<M>,
    /// 返回数据概述
    pub headers: Option<S>,
    /// 数据
    pub data: Value,
}

#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
pub struct PageInfor {
    /// 总条数
    pub total: u64,
    /// 页大小
    pub page_size: u32,
    /// 第几页
    pub page: u32,
}

#[derive(Debug, Default, Serialize, Deserialize, Clone, PartialEq)]
pub struct ExtractByClassFromDatabaseOption {}

#[async_trait::async_trait]
pub trait DataExtractor {
    /// 根据数据库获取到元数据
    async fn extract_by_class_from_database(
        &self,
        class: &Class,
        data_source: &DataSource,
        options: ExtractByClassFromDatabaseOption,
    ) -> anyhow::Result<DataValueSet<Class, PageInfor>>;
}
